package com.wingsoft.common.enums;

import com.wingsoft.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum SwitchEnum {
    FALSE(0, "否", "关闭"),
    TRUE(1, "是", "开启"),
    ;
    private final Integer code;
    private final String descYesOrNo;
    private final String descSwitch;

    public static SwitchEnum getEnumByCode(Integer code) {
        for (SwitchEnum value : SwitchEnum.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new ServiceException("是否枚举值不存在: " + code);
    }

    public static SwitchEnum getEnumByDescYesOrNo(String descYesOrNo) {
        for (SwitchEnum value : SwitchEnum.values()) {
            if (value.getDescYesOrNo().equals(descYesOrNo)) {
                return value;
            }
        }
        throw new ServiceException("开关枚举值不存在: " + descYesOrNo);
    }
}
